#!/usr/bin/env python
# -*- coding:utf-8 -*-

import requests
from lxml import etree
if __name__ == "__main__":
    # 爬取到页面源码数据
    url = 'https://tz.58.com/ershoufang/'
    # UA伪装
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.42'
    }
    page_text = requests.get(url=url, headers=headers).text
    # 数据解析
    tree = etree.HTML(page_text)
    div_list = tree.xpath('//section[@class="list"]/div')
    for div in div_list:
        title = div.xpath('div/a/div[2]/div[1]/div/h3/@title')
        print(title)
        break